package com.itheima.web;

import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
@WebServlet("/hello")
public class helloworld extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("浏览器 访问到我了哦。。。。");
        // 解析 request对象  解析请求参数  我们收到了浏览器的数据
        String name = request.getParameter("name");
        System.out.println("浏览器带着name值为:"+name+"来的");
        // 设置响应结果  结果给浏览器解析  response响应对象
        response.getWriter().write("Hello "+name);
        String age = request.getParameter("age");
        System.out.println("age="+age);
        //获取响应的url
        String url = request.getRequestURL().toString();
        System.out.println("url="+url);
        // 获取请求头
        String UserAgent=request.getHeader("User-Agent");
        System.out.println("UserAgent="+UserAgent);
        String scheme = request.getScheme();
        System.out.println("scheme="+scheme);
        String method = request.getMethod();
        System.out.println("method="+method);
    }
    }

